﻿Imports Microsoft.Office.Interop.Outlook

Namespace UI
    Public MustInherit Class pmBaseFolderTreeForm
        Protected _app As Outlook.Application
        Protected ReadOnly _mailToWorkWith As MailItem

        Protected _pmFoldertree As pmFoldertree
        Private ReadOnly _searchPattern As String

        Public Event ActionButtonClicked()

        Friend Sub New(ByVal App As Outlook.Application, ByVal mailToWorkWith As MailItem)
            If IsNothing(App) Then
                Throw New ArgumentNullException("App")
            End If

            If IsNothing(mailToWorkWith) Then
                Throw New ArgumentNullException("mailToWorkWith")
            End If

            _app = App
            _mailToWorkWith = mailToWorkWith


            ' This call is required by the Windows Form Designer.
            InitializeComponent()

        End Sub

        Private Sub pmBaseFolderTreeForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            initializeTreeview()
        End Sub

        Private Sub initializeTreeview()
            _pmFoldertree = New pmFoldertree(_mailToWorkWith, _app)
            Panel1.Controls.Add(_pmFoldertree)
        End Sub

        Public Sub SelectRelevantFolder(ByVal searchPattern As String)
            _pmFoldertree.searchPattern = searchPattern
            _pmFoldertree.SelectRelevantFolder()
        End Sub

        Private Sub CloseWindow()
            Me.Close()
        End Sub


#Region "Form Events"
        Private Sub btnSendAndFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoAction.Click
            RaiseEvent ActionButtonClicked()
            CloseWindow()
        End Sub

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            CloseWindow()
        End Sub

#End Region
    End Class

End Namespace